<?php
/**
 * Date: 2018/3/5
 * Time: 16:20
 * Author: zeronlee
 */
namespace App\Http\Controllers\Auth\Sso;

class Http{
    /**
     * 发送数据
     * @param String $url 请求的地址
     * @param Array $header 自定义的header数据
     * @param Array $content POST的数据
     * @return String
     */
    function tocurl ($url, $header, $content) {
        $ch = curl_init();
        if (substr($url, 0, 5) == 'https') {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);  // 从证书中检查SSL加密算法是否存在
        }
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($content));
        $response = curl_exec($ch);
        if ($error = curl_error($ch)) {
            die($error);
        }
        curl_close($ch);
        return $response;
    }
}